<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>login</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="icon" type="image/png" href="/static/assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="/static/assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI" />
    <link rel="stylesheet" href="/static/assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="/static/assets/css/admin.css">
    <link rel="stylesheet" href="/static/assets/css/app.css">
    <link rel="stylesheet" href="/static/css/me.css">
</head>
<body>
<div class="am-g myapp-login">
	<div class="myapp-login-logo-block  tpl-login-max">
		<div class="myapp-login-logo-text">
			<div class="myapp-login-logo-text">
				Amaze UI<span> Login</span> <i class="am-icon-skyatlas"></i>
			</div>
		</div>
		<div class="login-font">
			<i data-type="normal_type" class="active">账号密码登录 </i> or <i data-type="wechat_type"> 微信登录</i>
		</div>
		<div class="am-u-sm-10 login-am-center normal_type login_con">
			<div class="am-form">
				<fieldset>
					<div class="am-form-group">
						<input type="email" class="" id="username" placeholder="输入电子邮件">
					</div>
					<div class="am-form-group">
						<input type="password" class="" id="password" placeholder="设置个密码吧">
					</div>
					<p><button type="submit" class="am-btn am-btn-default" id="submit">登录</button></p>
                </fieldset>
			</div>
		</div>
        <div class="wechat_login login-am-center wechat_type login_con" style="display: none;">
            <div class="am-form">
				<fieldset>
					<div class="am-form-group ">
                        <div class="login_qr_code">
                            <img src="{{ url }}" alt="">
                        </div>
					</div>
                    <div class="am-form-group ">
                        <div class="login_status" id="status">请使用微信扫码</div>
					</div>
                </fieldset>
			</div>
        </div>
	</div>
</div>
<script src="/static/assets/js/jquery.min.js"></script>
<script src="/static/assets/js/amazeui.min.js"></script>
<script src="/static/assets/js/app.js"></script>
<script type="text/javascript">
    var login_flag = false, current_ajax = null, timer;
    function checkStatus() {
        var $tip = $('#status');
        if(current_ajax) current_ajax.abort();
        timer && clearTimeout(timer);
        current_ajax = $.get('/wx_auth/check_auth.do?uuid='+'{{ uuid }}',function(res){
            $tip.text(res.msg)
            if(res.state == 200 && res.status == 2){
                login_flag = true;
                setTimeout(function(){
                    window.location.href = '{{ next_url }}'
                },1*1000)
            }
        }).done(function(){
            if(!login_flag){
                timer = setTimeout(checkStatus,1500)
            }
        })
    }
    checkStatus();
    $('.login-font i').click(function(){
        var type = $(this).attr('data-type');
        $('.login-font i').removeClass('active');
        $(this).addClass('active');
        $('.login_con').hide();
        $('.'+type).show();
    })
    $('#submit').click(function(){
        var data = {
            username : $('#username').val(),
            password : $('#password').val(),
        }
        $.post('/login.do',data, function(res){
            if(res.state == 200){
                setTimeout(function(){
                    window.location.href = '{{ next_url }}'
                },1*1000)
            }
        })
    })
</script>
</body>
</html>